<template>
    <div>
        	<div id="slider" class="mui-slider">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="['mui-control-item',item.id==0? 'mui-active' : ' ' ]" v-for="item in showhead" :key="item.id" @click='showall(item.id)'>
							{{ item.title }}
						</a>
						
					</div>
				</div>

			</div>
			<ul class='all'>
				<router-link tag="li" :to="'/home/images/imageInfo'+item.id" v-for="item in showalldata" :key="item.id">
					<img v-lazy="item.img_url">
					<div class='image_text'>
						<h1>{{ item.title }}</h1>
						<div>{{ item.zhaiyao }}</div>
					</div>
				</router-link>
			</ul>
    </div>
</template>

<script>
import mui from '../../lib/mui/js/mui.min.js'

    export default{
        data(){
            return{
				showhead:[],
				showalldata:[]
			}
        },
        mounted() {
            this.headScroll()
		},
		created(){
			this.showdata()
			this.showall(0)
		},
        methods:{
           headScroll(){
               mui('.mui-scroll-wrapper').scroll({
				deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
														});
		   },
		   showdata(){
			   this.$http.get('api/getimgcategory').then(result=>{
				   if(result.body.status===0){
						result.body.message.unshift({title:'全部',id:0})
						this.showhead=result.body.message				
				   }               
			   })
		   },
		   showall(id){
             var test= []
			   this.$http.get('api/getimages/'+id).then(data=>{
               			if(data.body.status===0){	
							   data.body.message.forEach((item,i) => {								  
								  test.push(item)
							  										 });
				return this.$http.get('https://www.apiopen.top/meituApi?page=1')
						 			 			 }
			  													})
			.then(result2=>{   
				result2.body.data.forEach((item,i)=>{
				 	if(test[i]==undefined){
			    	return 
			 }
					test[i].img_url=item.url
			})
		})
					this.showalldata=test
		   }
        }
    }
</script>

<style lang="less" scoped>

image[lazy=loading] {
  width: 40px;
  height: 300px;
  margin: auto;
}
.all{
	
	list-style: none;
	margin: 0px;
	padding: 0px 4px;
	img{
		width: 100%;
		vertical-align: middle;
	}
	li{
		margin: 10px;
		position: relative;
		box-shadow: 0 0 9px #999;
		overflow-y: hidden;
	background-color: #fff
	
	}

	.image_text{
		position: absolute;
		bottom: 0px;
		  background-color: rgba(0, 0, 0, 0.4);
		  max-height: 84px;
          h1{
			font-size: 15px;
			color: #fff;
			
		  }
		  div{
			  font-size: 13px;
			  color: #fff;
		  }
	}
}
</style>
